﻿@using SCMS.UI.Areas.Admin.Models.SystemUser
@model SystemUserListModel
@{
    ViewBag.Title = "System Users";
}
<div class="partialViewCard">
    <div class="partialViewCardHeader">
        <h3>System Users</h3>
    </div>
    <br />
    @if (Model.Users.IsNotNullOrEmpty())
    {
        <div id="tablewrapper">
            <div id="tableheader">
                <div class="search">
                    <b>Search By:</b><br />
                    <select id="columns" onchange="sorter.search('query')"></select>
                    <input type="text" id="query" onkeyup="sorter.search('query')" />
                </div>
                <span class="details">
                    <div>Records <span id="startrecord"></span>-<span id="endrecord"></span> of <span id="totalrecords"></span></div>
                </span>
            </div>
            <br /><br /><br />
        <table width="98%" align="center" cellspacing="0" cellpadding="0" border="0" id="table" class="tinytable">
            <thead>
                <tr>
                    <th><h3>&nbsp;</h3></th><th><h3>Name</h3></th><th><h3>Email</h3></th><th><h3>Active</h3></th>
                    <th><h3>Locked</h3></th><th><h3>Finance Limit</h3></th><th><h3>Phone No.</h3></th>
                    <th><h3>&nbsp;</h3></th>
                </tr>
            </thead>
            <tbody>
            @foreach (var item in Model.Users)
            {
                <tr>
                    <td align="center">
                        @Ajax.ActionLink("View", "ViewUser", new { id = item.Id }, new AjaxOptions
                        {
                            UpdateTargetId = "AdminSystemUserDiv",
                            LoadingElementId = "loading",
                            Url = Url.Action("ViewUser/" + item.Id)
                        })
                    </td>
                    @if (@item.Staff != null)
                    {
                        <td align="left">@item.Staff.Person.FirstName @item.Staff.Person.OtherNames</td>
                        <td>@item.Staff.Person.OfficialEmail</td>
                    }
                    else
                    {
                        <td align="left">Not Set</td>
                        <td>Not Set</td>
                    }
                    
                    <td align="center">
                        @if (item.Active)
                        {
                            @item.Active
                        }
                        else
                        { 
                            <font color="red">
                                @item.Active
                            </font>
                        }
                    </td>
                    <td align="center">
                        @if (!item.Locked)
                        {
                            @item.Locked
                        }
                        else
                        { 
                            <font color="red">
                                @item.Locked
                            </font>
                        }
                    </td>
                    <td>
                        @if (item.Staff.FinanceLimitId.HasValue)
                        {
                            @item.Staff.FinanceLimit.Name
                        }
                        else
                        { 
                            @Html.Raw("Not Set")
                        }
                    </td>
                    <td align="center">@item.Staff.Person.OfficialPhone</td>
                    <td align="center">
                        @Html.ActionLink("Edit", "Edit", new { id = item.Id })
                    </td>
                </tr>
            }
            </tbody>
        </table>
        <div id="tablefooter">
                <div id="tablenav">
                    <div>
                        <img src="../../Content/images/pager/first.gif" width="16" height="16" alt="First Page" onclick="sorter.move(-1,true)" />
                        <img src="../../Content/images/pager/previous.gif" width="16" height="16" alt="Previous Page" onclick="sorter.move(-1)" />
                        <img src="../../Content/images/pager/next.gif" width="16" height="16" alt="Next Page" onclick="sorter.move(1)" />
                        <img src="../../Content/images/pager/last.gif" width="16" height="16" alt="Last Page" onclick="sorter.move(1,true)" />
                    </div>
                    <div>
                        <select id="pagedropdown"></select>
                    </div>
                    <div>
                        <a href="javascript:sorter.showall()">view all</a>
                    </div>
                </div>
                <div id="tablelocation">
                    <div>
                        <select onchange="sorter.size(this.value)">
                        <option value="5">5</option>
                            <option value="10">10</option>
                            <option value="20">20</option>
                            <option value="50" selected="selected">50</option>
                            <option value="100">100</option>
                        </select>
                        <span>Entries Per Page</span>
                    </div>
                    <div class="page">Page <span id="currentpage"></span> of <span id="totalpages"></span></div>
                </div>
            </div>
        </div>
    }
    else
    {
        <i>No System users defined</i>
    }
    <br />
</div>
